package com.changgou;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@SpringBootApplication
@EnableEurekaClient
public class SystemGatewayApplication {


    public static void main(String[] args) {

        SpringApplication.run(SystemGatewayApplication.class,args);
    }


    @Bean
    public KeyResolver ipKeyResolver(){
        //具体处理限流的逻辑，需要维护根据什么维度来限流
        return new KeyResolver() {
            @Override
            public Mono<String> resolve(ServerWebExchange exchange) {
                return Mono.just(exchange.getRequest().getRemoteAddress().getHostName());//限流的维度-可以设置为用户的IP地址
            }
        };
    }
}
